//
//  WithdrawActionViewController.m
//  EPBPro
//
//  Created by wucha on 2018/7/30.
//  Copyright © 2018年 fc. All rights reserved.
//

#import "WithdrawActionViewController.h"
#import "ResizeView.h"
#import "TokenAddressViewController.h"
#import "HttpTokenAction.h"

@interface WithdrawActionViewController ()

@end

@implementation WithdrawActionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.titleName = @"提现";
    ResizeView *resizeView = [[ResizeView alloc] initWithFrame:CGRectMake(0, StatusBarHeight+44, SCREEN_WIDTH, SCREEN_HEIGHT-StatusBarHeight-44)];
    [self.view addSubview:resizeView];
    [resizeView addResizeSubview:[self getSpaceResizeViewInfo:20]];
    [resizeView addResizeSubview:[self getNomarlNameResizeViewInfo:@"地址"]];
    [resizeView addResizeSubview:[self getAddResizeViewInfo]];
    [resizeView addResizeSubview:[self getSpaceResizeViewInfo:20]];
    [resizeView addResizeSubview:[self getNomarlNameResizeViewInfo:@"数量"]];
    [resizeView addResizeSubview:[self getEditResizeViewInfo]];
    [resizeView addResizeSubview:[self getSpaceResizeViewInfo:10]];
    [resizeView addResizeSubview:[self getNomarlNameResizeViewInfo:@"可用:0.00"]];
    [resizeView addResizeSubview:[self getSpaceResizeViewInfo:40]];

    [resizeView addResizeSubview:[self getNomarlNameResizeViewInfo:@"手续费" withValue:@"2000.00"]];
    [resizeView addResizeSubview:[self getSpaceResizeViewInfo:10]];
    [resizeView addResizeSubview:[self getNomarlNameResizeViewInfo:@"实际到账" withValue:@"2000.00"]];
    [resizeView addResizeSubview:[self getSpaceResizeViewInfo:40]];
    [resizeView addResizeSubview:[self getSubmitResizeViewInfo]];

}

-(ResizeViewInfo*)getSpaceResizeViewInfo:(int)height{
    ResizeViewInfo *resizeViewInfo = [[ResizeViewInfo alloc] init];
    resizeViewInfo.height = height;
    return resizeViewInfo;
    
}

-(ResizeViewInfo*)getNomarlNameResizeViewInfo:(NSString*)title{
    ResizeViewInfo *resizeViewInfo = [[ResizeViewInfo alloc] init];
    resizeViewInfo.height = 20;
    
    UILabel *label = [UILabel new];
    label.text = title;
    label.font = [UIFont systemFontOfSize:14];
    [resizeViewInfo addSubview:label];
    label.sd_layout.topSpaceToView(resizeViewInfo.view, 0).leftSpaceToView(resizeViewInfo.view, 15).rightSpaceToView(resizeViewInfo.view, 0).heightIs(20);
    
    return resizeViewInfo;
}

-(ResizeViewInfo*)getNomarlNameResizeViewInfo:(NSString*)title withValue:(NSString*)valueString{
    ResizeViewInfo *resizeViewInfo = [[ResizeViewInfo alloc] init];
    resizeViewInfo.height = 20;
    
    UILabel *label = [UILabel new];
    label.text = title;
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:14];
    [resizeViewInfo addSubview:label];
    label.sd_layout.topSpaceToView(resizeViewInfo.view, 0).leftSpaceToView(resizeViewInfo.view, 15).widthIs(200).heightIs(20);
    
    
    UILabel *vLabel = [UILabel new];
    vLabel.text = valueString;
    vLabel.textAlignment = NSTextAlignmentRight;
    vLabel.font = [UIFont systemFontOfSize:14];
    [resizeViewInfo addSubview:vLabel];
    vLabel.sd_layout.topSpaceToView(resizeViewInfo.view, 0).rightSpaceToView(resizeViewInfo.view, 15).widthIs(100).heightIs(20);
    
    return resizeViewInfo;
}

-(ResizeViewInfo*)getAddResizeViewInfo{
    ResizeViewInfo *resizeViewInfo = [[ResizeViewInfo alloc] init];
    resizeViewInfo.height = 70;

    UIButton *addButton = [UIButton new];
    addButton.backgroundColor = HexRGB(0xF8F8F8);
    addButton.titleLabel.font = [UIFont systemFontOfSize:16];
    addButton.titleLabel.numberOfLines = 0;
    addButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [addButton setTitle:@"添加提现地址" forState:UIControlStateNormal];
    [addButton setTitleColor:UIColor.lightGrayColor forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(addAddressAction:) forControlEvents:UIControlEventTouchUpInside];
    addButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, -10);
    [resizeViewInfo addSubview:addButton];
    addButton.sd_layout.leftSpaceToView(resizeViewInfo.view, 15).topSpaceToView(resizeViewInfo.view, 10).rightSpaceToView(resizeViewInfo.view, 15).heightIs(60);
    
    UIImageView *arrowImageView = [UIImageView new];
    arrowImageView.image = [UIImage imageNamed:@"arrow_right"];
    arrowImageView.contentMode = UIViewContentModeCenter;
    [resizeViewInfo addSubview:arrowImageView];
    arrowImageView.sd_layout.rightSpaceToView(resizeViewInfo.view, 25).topSpaceToView(resizeViewInfo.view, 10).bottomSpaceToView(resizeViewInfo.view, 0).widthIs(10);
    
    return resizeViewInfo;
}

-(void)addAddressAction:(id)sender{
    UIButton *button = sender;
    TokenAddressViewController *tokenAddressViewController = [[TokenAddressViewController alloc] initWithTokenBlock:^(TokenAddressInfo *tokenAddressInfo) {
        NSString *string = [NSString stringWithFormat:@"%@\n%@",tokenAddressInfo.addressName,tokenAddressInfo.address];
        [button setTitle:string forState:UIControlStateNormal];
    }];
    [self.navigationController pushViewController:tokenAddressViewController animated:YES];
}

-(ResizeViewInfo*)getEditResizeViewInfo{
    ResizeViewInfo *resizeViewInfo = [[ResizeViewInfo alloc] init];
    resizeViewInfo.height = 45;
    
    UITextField *textField = [UITextField new];
    textField.placeholder = @"最小提现xx";
    textField.font = [UIFont systemFontOfSize:16];
    [resizeViewInfo addSubview:textField];
    textField.sd_layout.leftSpaceToView(resizeViewInfo.view, 15).topSpaceToView(resizeViewInfo.view, 0).rightSpaceToView(resizeViewInfo.view, 15).heightIs(44);
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = DefaultLineColor;
    [resizeViewInfo addSubview:lineView];
    lineView.sd_layout.leftSpaceToView(resizeViewInfo.view, 15).bottomSpaceToView(resizeViewInfo.view, 0).rightSpaceToView(resizeViewInfo.view, 15).heightIs(1);
    
    return resizeViewInfo;
}

-(ResizeViewInfo*)getSubmitResizeViewInfo{
    ResizeViewInfo *resizeViewInfo = [[ResizeViewInfo alloc] init];
    resizeViewInfo.height = 40;
    
    UIButton *submitButton = [UIButton new];
    submitButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [submitButton setTitle:@"提交" forState:UIControlStateNormal];
    [submitButton addTarget:self action:@selector(submitAction:) forControlEvents:UIControlEventTouchUpInside];
    [submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    submitButton.backgroundColor = DefaultTenantColor;
    [resizeViewInfo addSubview:submitButton];
    submitButton.sd_layout.leftSpaceToView(resizeViewInfo.view, 40).topSpaceToView(resizeViewInfo.view, 0).bottomSpaceToView(resizeViewInfo.view, 0).widthIs(SCREEN_WIDTH-80);
    
    return resizeViewInfo;
}

-(void)submitAction:(id)sender{
    TokenWithDrawActionInfo *tokenWithDrawActionInfo = [[TokenWithDrawActionInfo alloc] init];
    [HttpTokenAction postTokenWithDraw:tokenWithDrawActionInfo block:^(id result, NSError *error) {
        if(!error){
            
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
